﻿function Get-TSMSession {    
    <#
        .SYNOPSIS
            Get TSM session
                    
        .DESCRIPTION
            The Get-TSMSession returns sessions running on the TSM server

        .PARAMETER SessionNumber
            The session number to search

        .EXAMPLE
            Get-TSMSession

        .NOTES
            Contributors:  David Seibel
            Last Revision Date: 09/01/2015

    #>
    [CmdletBinding()]
    Param(
        [Parameter(Position = 0)]
        [string]$SessionNumber
    )
    
    $whereProps = @()
    $whereProps += [PSCustomObject]@{ "Column" = "SESSION_ID"; "Operator" = "LIKE"; "Value" = $SessionNumber }

    $query = Format-TSMQuery -Table "SESSIONS" -Where $whereProps -OrderBy "SESSION_ID"
    $result = Invoke-TSMCommand -Command $query

    $defaultDisplaySet = 'SESSION_ID','STATE','BYTES_SENT','BYTES_RECEIVED','SESSION_TYPE','CLIENT_NAME'
    $typeDefinitions = @{
                        "SESSION_ID"     = [Int32]
                        "START_TIME"     = [DateTime]
                        "WAIT_SECONDS"   = [Int32]
                        "BYTES_SENT"     = [Int32]
                        "BYTES_RECEIVED" = [Int32]
                        "FAIL_OVER_MODE" = [bool]
                        }

    return Format-TSMData -Data $result -TypeDefinitions $typeDefinitions -DefaultDisplaySet $defaultDisplaySet
}